import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalPasswordPage(Base):
    """
    密码确认界面
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.password_home_btn = (By.XPATH, Personal.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.password_back_btn = (By.XPATH, Personal.RESOURCE_ID.format('ivBack'))

        # 页面标题
        self.password_title_text = (By.XPATH, Personal.RESOURCE_ID.format("verify_title"))

        # 密码文本
        self.password_list_identification_input_text = (By.XPATH, Personal.password_list_input_text.format(""))

        # 密码图标
        self.password_list_identification_input_select_icon = (By.XPATH, Personal.password_list_input_icon.format(""))

        # 删除按钮
        self.password_delete_btn = (By.XPATH, Personal.RESOURCE_ID.format("iv_delete_password"))

        # 密码数字按钮
        self.password_list_number_btn = (By.XPATH, Personal.password_list_number_btn.format(""))

        # 登录按钮
        self.password_submit_ok_btn = (By.XPATH, Personal.RESOURCE_ID.format("password_confirm_bt"))

        # 忘记密码按钮
        self.password_forget_password_btn = (By.XPATH, Personal.RESOURCE_ID.format("forget_passwd"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.password_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.password_home_btn)

    def get_title(self):
        """
        获取密码确认标题

        :return: 元素对象
        """
        return self.find_element_o(self.password_title_text)

    def get_list_identification_input(self, index=1):
        """
        获取密码输入文本
        index 最大值为4
        :return: 元素对象
        """
        self.password_list_identification_input_text = (By.XPATH, Personal.password_list_input_text.format(index))
        return self.find_element_o(self.password_list_identification_input_text)

    def get_list_identification_input_select(self, index=1):
        """
        获取密码输入图标
        index 最大值为4
        :return: 元素对象
        """
        self.password_list_identification_input_select_icon = (By.XPATH, Personal.password_list_input_icon.format(index))
        return self.find_element_o(self.password_list_identification_input_select_icon)

    def click_delete(self):
        """
        点击删除按钮

        :return: None
        """
        self.click_element(self.password_delete_btn)

    def click_list_number(self, index):
        """
        点击数字输入按钮
        index 为输入的数字,取值范围为1-10
        :return: None
        """
        self.password_list_number_btn = (By.XPATH, Personal.password_list_number_btn.format(index))
        self.click_element(self.password_list_number_btn)

    def get_list_number(self):
        """
        获取数字
        index 为输入的数字,取值范围为1-10
        :return: None
        """
        return self.find_element_o(self.password_list_number_btn)

    def click_submit_ok(self):
        """
        点击确认按钮

        :return: None
        """
        self.click_element(self.password_submit_ok_btn)

    def get_submit_ok(self):
        """
        获取确认按钮状态

        :return: 元素对象
        """
        return self.find_element_o(self.password_submit_ok_btn)

    def click_forget_password(self):
        """
        点击忘记密码按钮

        :return: None
        """
        self.click_element(self.password_forget_password_btn)

    def is_display_personal_password(self):
        """
        是否进入密码确认界面

        :return: bool
        """
        return self.is_display(self.password_title_text)

    def is_toast_personal_password(self):
        """
        密码输入是否一致

        :return: bool
        """
        return self.is_toast_exist(text="两次密码不同,请重新设置")
